<template>
	<div>
		<el-row >
			<el-col :span="18">
				<el-row >
					<el-col :span="24">
						<span>自定义时间段
							<b style="color:rgb(103,106,108);font-size: 10px;">（限一年内,先选择截止时间）</b>
						</span>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="1" class='labelCol'>
						<p class="labelText">周期开始:</p>
					</el-col>
					<el-col :span="6">
						<el-date-picker size="small" style="width: 95%;" v-model="startTime" format="yyyy-MM-dd" :editable=false disabled type="date" placeholder="起始">
						</el-date-picker>
					</el-col>
					<el-col :span="1" class='labelCol'>
						<p class="labelText">周期结束:</p>
					</el-col>
					<el-col :span="6">
						<el-date-picker size="small" style="width: 95%;" v-model="condition.baseTime" format="yyyy-MM-dd" :editable=false type="date" @change="changetime" placeholder="结束" :clearable=false>
						</el-date-picker>
					</el-col>
					<el-col :span="4" style="padding-left: 0px;text-align: left">
						<el-button type="primary" size="small" v-on:click='baseQuery'>查询</el-button>
						<el-button type="primary" size="small" @click="baseOut" v-if="btnGroup.out">导出</el-button>
					</el-col>
				</el-row>
	
				<el-row >
					<el-col :span="1" class='labelCol'>
						<p class="labelText">选择车系:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.series" multiple placeholder="请选择车系" clearable>
							<el-option v-for="item in seriesComboData" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>

					<el-col :span="1" class='labelCol'>
						<p class="labelText">选择车龄:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.age" multiple placeholder="请选择车龄" clearable>
							<el-option v-for="item in carAgeCombo" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
					<el-col :span="1" class='labelCol'>
						<p class="labelText">选择人员:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.SA" placeholder="选择人员" clearable>
							<el-option v-for="item in SAComboData" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="1" class='labelCol'>
						<p class="labelText">选择里程:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.runMile" multiple placeholder="请选择里程" clearable>
							<el-option v-for="item in lengthComboData" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
					<el-col :span="1" class='labelCol'>
						<p class="labelText">基盘类别:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.baseType" placeholder="基盘类别" clearable>
							<el-option v-for="item in baseTypeComboData" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
					<el-col :span="1" class='labelCol'>
						<p class="labelText">客户状态:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.lost.type" placeholder="客户状态" clearable>
							<el-option v-for="item in statusComboData" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
				</el-row>
				<el-row >

					<el-col :span="1" class='labelCol'>
						<p class="labelText">VIN:</p>
					</el-col>
					<el-col :span="5">
						<el-input size="small" style="" v-model="condition.vin" placeholder="请输入VIN">
						</el-input>
					</el-col>
					<el-col :span="1" class='labelCol'>
						<p class="labelText">车牌尾号:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.wh" multiple placeholder="车牌尾号" clearable>
							<el-option v-for="item in plateNumWHCombo" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
					<el-col :span="1" class='labelCol'>
						<p class="labelText">车牌尾数:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.ws" multiple placeholder="车牌尾数" clearable>
							<el-option v-for="item in plateNumWSCombo" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
				</el-row>
				
				<el-row >
					<el-col :span="1" class='labelCol'>
						<p class="labelText">行政区划:</p>
					</el-col>

					<el-col :span="5">
						<el-select size="small" style="width: 100%;" v-model="condition.xzarea" multiple placeholder="行政区域" clearable>
							<el-option v-for="item in  areaCombo " :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-col>
					<el-col :span="1" class='labelCol'>
						<p class="labelText">开始日期:</p>
					</el-col>
					<el-col :span="5">
						<el-date-picker size="small" style="width:95%" v-model="condition.lost.start" format="yyyy-MM-dd" :editable=false type="date" placeholder="开始日期">
						</el-date-picker>
					</el-col>
					<el-col :span="1" class='labelCol'>
						<p class="labelText">结束日期:</p>
					</el-col>
					<el-col :span="5">
						<el-date-picker size="small" style="width:95%" v-model="condition.lost.end" format="yyyy-MM-dd" :editable=false type="date" placeholder="结束日期">
						</el-date-picker>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="1" class="labelCol">
						<p class="labelText">维系人:</p>
					</el-col>
					<el-col :span="5">
						<el-input size="small" v-model="condition.wxId" style="width: 95%;" placeholder="请输入维系人姓名">
						</el-input>
					</el-col>
					<el-col :span="1" class="labelCol">
						<p class="labelText">销售顾问:</p>
					</el-col>
					<el-col :span="5">
						<el-input size="small" v-model="condition.saler" style="width: 95%;" placeholder="请输入销售顾问">
						</el-input>
					</el-col>
					<el-col :span="1" class="labelCol">
						<p class="labelText">市场活动:</p>
					</el-col>
					<el-col :span="5">
						<el-select size="small" v-model="condition.marketTag" style="width: 100%;" placeholder="请选择活动" clearable>
							<el-option label="润享计划" value="润享"></el-option>
						</el-select>
					</el-col>
				</el-row>
				
				<el-row>
					<el-col :span="24">
						<el-table :data="tableData.dataList" v-loading.body="loading" height="460" element-loading-text="正在加载，请稍候..." stripe border>
							<el-table-column type="index" label="序号" width="70">
							</el-table-column>
							<el-table-column prop="vin" label="VIN" width="170">
							</el-table-column>
							<el-table-column prop="plateNum" label="车牌号" width="100">
							</el-table-column>
							<el-table-column prop="active" label="活跃等级" width="90" align="right">
							</el-table-column>
							<el-table-column prop="series" label="车型" width="150">
							</el-table-column>
							<el-table-column prop="ownerName" label="车主" width="120">
							</el-table-column>
							<el-table-column prop="fromCompany" label="本公司购车" width="110">
							</el-table-column>
							<el-table-column prop="cz" label="产值" width="80" align="right" :formatter="fixedCz">
							</el-table-column>
							<el-table-column prop="jccs" label="进场次数" width="90" align="right">
							</el-table-column>
							<el-table-column prop="carAge" label="车龄" width="90" align="right">
							</el-table-column>

						</el-table>
						<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total">
						</el-pagination>
					</el-col>
				</el-row>
			</el-col>
			<el-col :span="6">
				<el-row :gutter="24">
					<el-col :span="24">
						<div style="padding:20,20,20,20;">
							<el-row :gutter="24">
								<el-col :span="24">
									<span style="font-size: 1.2em; color:rgb(103,106,108);">区间客户基盘数</span>
								</el-col>
								<el-col :span="24">
									<span style="font-size: 1.8em; color:rgb(103,106,108);">&nbsp;&nbsp;&nbsp;{{baseCount}}</span>
								</el-col>
								<el-col :span="24" style="text-align: right">
									<span style="font-size: 0.8em; color:rgb(26,179,148);">{{moment(startTime).format("YYYY-MM-DD")}}-{{moment(condition.baseTime).format("YYYY-MM-DD")}}</span>
								</el-col>
							</el-row>
						</div>
					</el-col>
					<el-col :span="24">
						<div style="height: 1.5em;"></div>
					</el-col>
					<el-col :span="24">
						<div style="padding:20,20,20,20;">
							<el-row :gutter="24">
								<el-col :span="24">
									<span style="font-size: 1.2em; color:rgb(103,106,108);">区间基盘增长数量</span>
								</el-col>
								<el-col :span="24">
									<span style="font-size: 1.8em; color:rgb(103,106,108);">&nbsp;&nbsp;&nbsp;{{growCount}}</span>
								</el-col>
							</el-row>
						</div>
						<div id="charts">
							<div id="main" :style="{width:'100%',height:'350px'}"></div>
						</div>
					</el-col>
					<el-col :span="24" style="text-align: right">
						<span style="font-size: 0.8em; color:rgb(26,179,148);">{{moment(startTime).format("YYYY-MM-DD")}}-{{moment(condition.baseTime).format("YYYY-MM-DD")}}</span>
					</el-col>
					<el-col :span="24">
						<div style="height: 1.5em;"></div>
					</el-col>
					<el-col :span="24">
						<div style="padding:20,20,20,20;">
							<el-row :gutter="24">
								<el-col :span="24">
									<span style="font-size: 1.2em; color:rgb(103,106,108);">区间基盘增长率</span>
								</el-col>
								<el-col :span="24">
									<span style="font-size: 1.8em; color:rgb(103,106,108);">&nbsp;&nbsp;&nbsp;{{growLv}}</span>
								</el-col>
								<el-col :span="24" style="text-align: right">
									<span style="font-size: 0.8em; color:rgb(26,179,148);">{{moment(startTime).format("YYYY-MM-DD")}}-{{moment(condition.baseTime).format("YYYY-MM-DD")}}</span>
								</el-col>
							</el-row>
						</div>
					</el-col>
					<el-col :span="24">
						<div style="height: 1.5em;"></div>
					</el-col>
					<el-col :span="24">
						<div style="padding:20,20,20,20;">
							<el-row :gutter="24">
								<el-col :span="24">
									<span style="font-size: 1.2em; color:rgb(103,106,108);">区间客户流失量</span>
								</el-col>
								<el-col :span="24">
									<el-button type="text" @click="lostButton">
										<span style="font-size: 1.8em;">&nbsp;&nbsp;&nbsp;{{lostCount}}</span>
									</el-button>
								</el-col>
								<el-col :span="24" style="text-align: right">
									<span style="font-size: 0.8em; color:rgb(26,179,148);">{{moment(startTime).format("YYYY-MM-DD")}}-{{moment(condition.baseTime).format("YYYY-MM-DD")}}</span>
								</el-col>
							</el-row>
						</div>
					</el-col>
					<el-col :span="24">
						<div style="height: 1.5em;"></div>
					</el-col>
					<el-col :span="24">
						<div style="padding:20,20,20,20;">
							<el-row :gutter="24">
								<el-col :span="24">
									<span style="font-size: 1.2em; color:rgb(103,106,108);">区间客户流失率</span>
								</el-col>
								<el-col :span="24">
									<span style="font-size: 1.8em; color:rgb(103,106,108);">&nbsp;&nbsp;&nbsp;{{lostLv}}</span>
								</el-col>
								<el-col :span="24" style="text-align: right">
									<span style="font-size: 0.8em; color:rgb(26,179,148);">{{moment(startTime).format("YYYY-MM-DD")}}-{{moment(condition.baseTime).format("YYYY-MM-DD")}}</span>
								</el-col>
							</el-row>
						</div>
					</el-col>
					<el-col :span="24">
						<div style="height: 1.5em;"></div>
					</el-col>
					<el-col :span="24">
						<div style="padding:20,20,20,20;">
							<el-row :gutter="24">
								<el-col :span="24">
									<span style="font-size: 1.2em; color:rgb(103,106,108);">年度客户活跃度</span>
								</el-col>
								<el-col :span="24">
									<span style="font-size: 1.8em; color:rgb(103,106,108);">&nbsp;&nbsp;&nbsp;{{activeLv}}</span>
								</el-col>
								<el-col :span="24" style="text-align: right">
									<span style="font-size: 0.8em; color:rgb(26,179,148);">{{moment(startTime).format("YYYY-MM-DD")}}-{{moment(condition.baseTime).format("YYYY-MM-DD")}}</span>
								</el-col>
							</el-row>
						</div>
					</el-col>
					<el-col :span="24">
						<div style="height: 1.5em;"></div>
					</el-col>
					<!--<el-col :span="24">																																																																																																																									</el-col>-->
				</el-row>
			</el-col>
		</el-row>

		<!--流失车辆详情-->
		<el-dialog
			title="流失车辆详情"
  			size="large"
  			v-model="lostDetailDialog" >

  			<el-row>
					<el-col :span="24">
						<el-table :data="tableDataLost.dataList" v-loading.body="loading2" height="460" element-loading-text="正在加载，请稍候..." stripe border>
							<!--<el-table-column type="index" label="序号" width="70">
							</el-table-column>-->
							<el-table-column prop="vin" label="VIN" width="180">
							</el-table-column>
							<el-table-column prop="plateNum" label="车牌号" width="120">
							</el-table-column>
							<el-table-column prop="active" label="活跃等级" width="100" align="right">
							</el-table-column>
							<el-table-column prop="series" label="车型" width="150">
							</el-table-column>
							<el-table-column prop="ownerName" label="车主" width="180">
							</el-table-column>
							<el-table-column prop="series" label="车系" width="180">
							</el-table-column>
							<el-table-column prop="fromCompany" label="本公司购车" width="110">
							</el-table-column>
							<el-table-column prop="configure" label="配置" width="240" align="right">
							</el-table-column>
							<el-table-column prop="carAge" label="车龄" width="120" align="right">
							</el-table-column>
							<el-table-column prop="lostStartDate" label="流失时间" width="120" align="right">
							</el-table-column>

						</el-table>
						<el-pagination small @size-change="handleSizeChange2" @current-change="handleCurrentChange2" :current-page="CurentPage2" :page-sizes="page2.pageSizes" :page-size="page2.pageSize" layout=" total,prev, pager, next" :total="tableDataLost.total">
						</el-pagination>
					</el-col>
				</el-row>

  		</el-dialog>



	</div>
</template>
<script>
import moment from 'moment'
import echarts from 'echarts'
export default {
	data: function() {
		return {
			lostDetailDialog:false,
			area: '',
			brand: '',
			companyId: window.localStorage.getItem("companyId"),
			areaCombo2: [],
			brandCombo: [],
			companyCombo: [],
			msg: "123",
			//页码数
			CurentPage: 1,
			//每页的数量
			page: this.page,
			//页码数
			CurentPage2: 1,
			//每页的数量
			page2: this.page,
			//查询条件
			//condition: {},
			//查询条件车系
			seriesComboData: [],
			//sa
			SAComboData: [],
			/*---------------右边框-------------*/
			//基盘数
			baseCount: 0,
			//来源占比
			growCount: '',
			//增长率
			growLv: '',
			//流失数量
			lostCount: '',
			//流失率
			lostLv: '',
			//活跃度
			activeLv: '',
			/*---------------右边框-------------*/
			//分组数据
			tableData: {
				total: 0,
				dataList: []
			},
			//流失车辆
			tableDataLost: {
				total: 0,
				dataList: []
			},
			//开始时间
			startTime: this.moment(new Date()).subtract(1, "years").add(1, "days").format("YYYY-MM-DD"),
			lengthComboData: [{
				label: '1万公里以内',
				value: '0-1'
			}, {
				label: '1-3万公里',
				value: '1-3'
			}, {
				label: '3-5万公里',
				value: '3-5'
			}, {
				label: '5-8万公里',
				value: '5-8'
			}, {
				label: '8-10万公里',
				value: '8-10'
			}, {
				label: '10万公里以上',
				value: ''
			},],
			//延保类型
			baseTypeComboData: [{
				label: '有效基盘',
				value: '0'
			}, {
				label: '增长：新车',
				value: '1'
			}, {
				label: '增长：流失返回',
				value: '2'
			}, {
				label: '增长：社会招揽',
				value: '3'
			}],
			//车龄
			carAgeCombo: [{
				label: '一年',
				value: '1'
			}, {
				label: '两年',
				value: '2'
			}, {
				label: '三年',
				value: '3'
			}, {
				label: '四年',
				value: '4'
			}, {
				label: '五年',
				value: '5'
			}, {
				label: '六年',
				value: '6'
			}, {
				label: '七年',
				value: '7'
			}, {
				label: '八年',
				value: '8'
			}, {
				label: '八年以上',
				value: '9'
			}],
			//车龄
			plateNumWSCombo: [{
				label: '0',
				value: '0'
			}, {
				label: '1',
				value: '1'
			}, {
				label: '2',
				value: '2'
			}, {
				label: '3',
				value: '3'
			}, {
				label: '4',
				value: '4'
			}, {
				label: '5',
				value: '5'
			}, {
				label: '6',
				value: '6'
			}, {
				label: '7',
				value: '7'
			}, {
				label: '8',
				value: '8'
			}, {
				label: '9',
				value: '9'
			},],
			//车牌尾号
			plateNumWHCombo: [{
				label: '0',
				value: '0'
			}, {
				label: '1',
				value: '1'
			}, {
				label: '2',
				value: '2'
			}, {
				label: '3',
				value: '3'
			}, {
				label: '4',
				value: '4'
			}, {
				label: '5',
				value: '5'
			}, {
				label: '6',
				value: '6'
			}, {
				label: '7',
				value: '7'
			}, {
				label: '8',
				value: '8'
			}, {
				label: '9',
				value: '9'
			}, {
				label: 'A',
				value: 'A'
			}, {
				label: 'B',
				value: 'B'
			}, {
				label: 'C',
				value: 'C'
			}, {
				label: 'D',
				value: 'D'
			}, {
				label: 'E',
				value: 'E'
			}, {
				label: 'F',
				value: 'F'
			}, {
				label: 'G',
				value: 'G'
			}, {
				label: 'H',
				value: 'H'
			}, {
				label: 'I',
				value: 'I'
			}, {
				label: 'J',
				value: 'J'
			}, {
				label: 'K',
				value: 'K'
			}, {
				label: 'L',
				value: 'L'
			}, {
				label: 'M',
				value: 'M'
			}, {
				label: 'N',
				value: 'N'
			}, {
				label: 'O',
				value: 'O'
			}, {
				label: 'P',
				value: 'P'
			}, {
				label: 'Q',
				value: 'Q'
			}, {
				label: 'R',
				value: 'R'
			}, {
				label: 'S',
				value: 'S'
			}, {
				label: 'T',
				value: 'T'
			}, {
				label: 'U',
				value: 'U'
			}, {
				label: 'V',
				value: 'V'
			}, {
				label: 'W',
				value: 'W'
			}, {
				label: 'X',
				value: 'X'
			}, {
				label: 'Y',
				value: 'Y'
			}, {
				label: 'Z',
				value: 'Z'
			},],
			//状态
			statusComboData: [{
				label: '按天流失',
				value: '0'
			}, {
				label: '按月流失',
				value: '1'
			}],
			//查询条件的对象
			condition: {
				area: '',
				brand: '',
				companyId: window.localStorage.getItem("companyId"),
				SA: '',
				series: [],
				age: [],
				runMile: [],
				baseType: '',
				lost: {
					type: '',
					start: '',
					end: ''
				},
				baseTime: new Date(),
				wh: [],
				ws: [],
				vin: '',
				xzarea : [],
				/*新增维系人、销售顾问 2017、09、18 Liu*/
				wxId:"",
				saler:"",
				marketTag:"",
			},
			rightDate: '',
			//字典转换值
			deptConvertData: {},
			//短信名称转换值
			typeConvertData: {},

			//业务系统字典
			moduleCombo: [],
			xc: 0,
			lsfh: 0,
			shzl: 0,
			areaCombo: [],
			loading: false,
			loading2: false,
			btnGroup: {}
		}
	},

	methods: {

		lostButton:function(){
			this.$data.lostDetailDialog = true;
			this.lostCountDetail();
			//alert("hello");
		},
		//查询
		baseQuery: function() {
			//this.$data.condition.baseTime = this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD");
			if (this.$data.condition.lost.start) {
				this.$data.condition.lost.start = this.moment(this.$data.condition.lost.start).format("YYYY-MM-DD")
			}else{

			}
			if (this.$data.condition.lost.end) {
				this.$data.condition.lost.end = this.moment(this.$data.condition.lost.end).format("YYYY-MM-DD")
			}else{

			}
			if (this.$data.condition.baseTime) {
				this.$data.condition.baseTime = this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD")
			}else{

			}
			if (this.$data.companyId == "") {
				this.$message.error("请选择公司！");
			} else {
				this.$data.condition.area = this.$data.area;
				this.$data.condition.brand = this.$data.brand;
				this.$data.condition.companyId = this.$data.companyId;
				this.$data.loading = true;
				this.$http.post(this.API_ROOT + '/car/base/page', this.$data.condition, {
					params: {
						start: this.$data.CurentPage,
						limit: this.page.pageSize
					}
				})
					.then(resp => {
						if (resp.data.success) {
							//debugger;
							//this.$message(resp.data.msg);
							resp.data.total = parseInt(resp.data.total);
							// es5写法
							this.$data.tableData = resp.data;
							//this.baseQuery(this.$data.curTreeDeptId);
							//this.$data.exFormShow = false;
							this.$data.loading = false;
						} else {
							//debugger;
							this.$message.error(resp.data.msg);
							this.$data.loading = false;

						}
						//this.$data.condition.baseTime = this.moment(this.$data.condition.baseTime);
					}, resp => { });
				//调用右侧数据刷新 基盘数
				this.baseCountGetData();
				//获取右侧数据增长量
				this.growCountGetData();
				//获取右侧数据 增长率
				this.growLvGetData();
				//获取右侧数据 流失量
				this.lostCountGetData();
				//获取右侧数据 流失率
				this.lostLvGetData();
				//获取右侧数据 活跃度
				this.activeLvGetData();

			}

		},
		baseOut: function() { //导出
			if (this.$data.condition.lost.start) {
				this.$data.condition.lost.start = this.moment(this.$data.condition.lost.start).format("YYYY-MM-DD")
			}
			if (this.$data.condition.lost.end) {
				this.$data.condition.lost.end = this.moment(this.$data.condition.lost.end).format("YYYY-MM-DD")
			}
			if (this.$data.condition.baseTime) {
				this.$data.condition.baseTime = this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD")
			}

			this.$http.post(this.API_ROOT + '/car/base/exportExecl', this.$data.condition, {
				params: {
					start: this.$data.CurentPage,
					limit: this.page.pageSize
				}
			})
				.then(resp => {
					if (resp.data.success) {
						debugger;
						window.location.href = this.API_ROOT + "/base/exp/xlsx?fileId=" + resp.data.data + "&&fileName=基盘车辆数据-" + this.moment().format("YYYYMMDDHHmmss") + "&&fileType=xlsx";
					}
				}, resp => { });

			//				this.$http.post(this.API_ROOT + '/car/base/exportExecl', this.$data.condition)
			//					.then(resp => {
			//						window.location.href = this.API_ROOT + '/downlocal/' + resp.data.data + ".xlsx"
			//					}, resp => {});
		},
		//列表，分页大小切换
		handleSizeChange: function() { },
		//列表,当前页切换
		handleCurrentChange: function(currentPage) {
			this.$data.CurentPage = currentPage;
			//this.$data.dictGroup = '';
			this.baseQuery();
		},
		/*流失车辆详情*/
		//列表，分页大小切换
			handleSizeChange2: function() { },
			//列表,当前页切换
			handleCurrentChange2: function(currentPage) {
				this.$data.CurentPage2 = currentPage;
				//this.$data.dictGroup = '';
				this.lostCountDetail();
			},

		//时间变更回调函数
		changetime: function(datess) {
			if (datess != undefined) {
				this.$data.startTime = this.moment(datess).subtract(1, "years").add(1, "days").format("YYYY-MM-DD")
			}
		},

		//状态转换
		statusCov: function(row, column) {
			return row.status == "0" ? '已停用' : '已启用';
		},
		//组织机构转换
		deptCov: function(row, column) {
			return this.$data.deptConvertData[row.companyId];
		},
		//组织机构转换
		typeCov: function(row, column) {
			return this.$data.typeConvertData[row.type];
		},
		//获取右侧数据 基盘数
		baseCountGetData: function() {

			this.$http.get(this.API_ROOT + '/car/base/baseCount', {
				params: {
					endDate: this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD"),
					SA: this.$data.condition.SA,
					companyId: this.$data.companyId,
				}
			})
				.then(resp => {
					if (resp.data.success) {
						//debugger;
						//this.$message(resp.data.msg);
						this.$data.baseCount = resp.data.data;
					} else {
						//debugger;
						this.$message.error(resp.data.msg);

					}
					//this.$data.condition.baseTime = this.moment(this.$data.condition.baseTime);
				}, resp => { });
		},
		//获取右侧数据增长量
		growCountGetData: function() {

			this.$http.get(this.API_ROOT + '/car/base/growCount', {
				params: {
					endDate: this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD"),
					SA: this.$data.condition.SA,
					companyId: this.$data.companyId,
				}
			}).then((response) => {
				if (response.data.dataList != undefined) {

					for (var i = 0; i < response.data.dataList.length; i++) {
						switch (response.data.dataList[i].baseType) {
							case "1":
								this.$data.xc = response.data.dataList[i].count
								break;
							case "2":
								this.$data.lsfh = response.data.dataList[i].count
								break;
							case "3":
								this.$data.shzl = response.data.dataList[i].count
								break;
						}

					}

				}
				this.$data.growCount = this.$data.xc + this.$data.lsfh + this.$data.shzl;
				this.mounteds();
			}, (response) => { });
		},
		//获取右侧数据 增长率
		growLvGetData: function() {

			this.$http.get(this.API_ROOT + '/car/base/growLv', {
				params: {
					endDate: this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD"),
					SA: this.$data.condition.SA,
					companyId: this.$data.companyId,
				}
			}).then((response) => {
				this.$data.growLv = response.data.data;
			}, (response) => { });
		},
		//获取右侧数据 流失量
		lostCountGetData: function() {

			this.$http.get(this.API_ROOT + '/car/base/lostCount', {
				params: {
					endDate: this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD"),
					SA: this.$data.condition.SA,
					companyId: this.$data.companyId,
				}
			}).then((response) => {
				this.$data.lostCount = response.data.data;
			}, (response) => { });
		},
		//流失详情
		lostCountDetail: function() {
			this.$data.loading2 = true;
			debugger;
			this.$http.get(this.API_ROOT + '/car/base/lostCountDetail', {
				params: {
					endDate: this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD"),
					SA: this.$data.condition.SA,
					companyId: this.$data.companyId,
					start: this.$data.CurentPage2,
					limit: this.page2.pageSize
				}
			}).then((response) => {
				this.$data.tableDataLost.total = parseInt(response.data.total);
				this.$data.tableDataLost.dataList = response.data.dataList;
				this.$data.loading2 = false;
			}, (response) => { });
		},
		//获取右侧数据 流失率
		lostLvGetData: function() {

			this.$http.get(this.API_ROOT + '/car/base/lostLv', {
				params: {
					endDate: this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD"),
					SA: this.$data.condition.SA,
					companyId: this.$data.companyId,
				}

			}).then((response) => {
				this.$data.lostLv = response.data.data;
			}, (response) => { });
		},
		//获取右侧数据 活跃度
		activeLvGetData: function() {

			this.$http.get(this.API_ROOT + '/car/base/activeLv', {
				params: {
					endDate: this.moment(this.$data.condition.baseTime).format("YYYY-MM-DD"),
					SA: this.$data.condition.SA,
					companyId: this.$data.companyId,
				}

			}).then((response) => {
				this.$data.activeLv = response.data.data;
			}, (response) => { });
		},

		queryDeptCovert: function() {
			this.$http.get(this.API_ROOT + '/rbac/dept/convert', {
				params: {
					root: "0",
					type: ""
				}
			}).then((response) => {
				this.$data.deptConvertData = response.data;
			}, (response) => { });
		},
		msgTypeDeptCovert: function() {
			this.$http.get(this.API_ROOT + '/base/dict/convert', {
				params: {
					group: "exInsuranceType"
				}
			}).then((response) => {
				this.$data.typeConvertData = response.data;
			}, (response) => { });
		},
		mounteds: function() {
			// 基于准备好的dom，初始化echarts实例
			var myChart = echarts.init(document.getElementById('main'));
			// 指定图表的配置项和数据
			var option = {
				title: {
					text: '来源占比',
					x: 'center'
				},
				tooltip: {
					trigger: 'item',
					formatter: "{a} <br/>{b} : {c} ({d}%)"
				},
				legend: {
					orient: 'vertical',
					left: 'left',
					data: ['新车', '流失返回', '社会招揽',]
				},
				series: [{
					name: '来源占比',
					type: 'pie',
					radius: '55%',
					//roseType: 'angle',
					data: [{
						value: this.$data.xc,
						name: '新车'
					},
					{
						value: this.$data.lsfh,
						name: '流失返回'
					},
					{
						value: this.$data.shzl,
						name: '社会招揽'
					},
					]
				}]
			};
			// 使用刚指定的配置项和数据显示图表。
			myChart.setOption(option);
		},
		//月产值保留两位小数
		fixedCz: function(row, column) {
			return Number(row.cz).toFixed(2);
		},
		//获取公司信息
		getCompanyInfo: function() {
			//this.$data.data.companyId = ""; //清空单位
			this.$data.companyId = ""; //清空单位
			this.$data.companyCombo = [];
			debugger;
			this.$http.get(this.API_ROOT + "/rbac/dept/all", {
				params: {
					area: this.$data.area,
					brand: this.$data.brand
				}
			}).then(resp => {
				this.$data.companyCombo = resp.data.dataList;
				if (this.$data.companyCombo.length > 0) {
					this.$data.companyId = this.$data.companyCombo[0].id;
				}
			});
		},

		//huoqu chexi
		getService: function() { //加车系
			this.$data.seriesComboData = [];
			this.$data.condition.series = [];

			this.$http.get(this.API_ROOT + '/base/car/combo', {
				params: {
					companyId: this.$data.companyId
				}
			}).then((response) => {
				// success callback
				this.$data.seriesComboData = response.data;
			}, (response) => {
				// error callback
			});
		},
		//huoqu 人员
		getPeople: function() {
			this.$data.SAComboData = [];
			this.$data.condition.SA = '';

			//加载sa
			this.$http.get(this.API_ROOT + '/crm/config/userComBo', {
				params: {
					companyId: this.$data.companyId
				}
			}).then((response) => {
				// success callback
				this.$data.SAComboData = response.data;
			}, (response) => {
				// error callback
			});
		},
	},
	//表单创建时执行
	created: function() {
	
		//加载饼状图
		//this.testEcharts();
		//列表查询
		//this.baseQuery();
		//查询部门转换
		this.queryDeptCovert();

		//短信名称转换
		this.msgTypeDeptCovert();
		//加载模块类型
		this.$http.get(this.API_ROOT + '/base/dict/combo', {
			params: {
				group: "msgType"
			}
		}).then((response) => {
			// success callback
			this.$data.moduleCombo = response.data;
		}, (response) => {
			// error callback
		});

		//配置按钮
		this.$http({
			method: 'GET',
			url: this.API_ROOT + '/rbac/login/btn', //url 输出 按照车牌号的 车牌号
			params: { //发送的参数
				resPath: "crm/customer/base", //crm/customer/base
			}
		}).then(function(resp) {
			var btnData = resp.data.dataList;

			var temp = {};

			for (var i = 0; i < btnData.length; i++) {

				var btnName = btnData[i].btnName;

				temp[btnName] = true;

			}
			debugger;
			Object.assign(this.$data.btnGroup, temp);
		}, function(error) {
			// error
		})
	}
}
</script>